"""
把表member_level_sku的商品名为 某某的，的 字段加一
"""
# 导包
import pymysql

# 定义全局变量
conn = None
cursor = None
try:
    # 创建连接
    conn = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="mengyue", database="jiuchao",
                           charset="utf8")
    # 创建游标
    cursor = conn.cursor()
    # 执行update语句
    cursor.execute("update member_level_sku set discount = discount + 1 where spu_name = '测试商品2号酒';")
    # 执行完增删改语句看affected rows受影响的行
    print("Affected rows:", conn.affected_rows())
    # 提交事务
    conn.commit()
except Exception as err:
    print("更新sql失败", str(err))
    # 回滚事务
    conn.rollback()
finally:
    # 关闭游标
    cursor.close()
    # 关闭连接
    conn.close()
